package com.itcast.tanhuaserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itcast.tanhuaserver.domain.UserInfo;
import com.itcast.tanhuaserver.mapper.UserInfoMapper;
import com.itcast.tanhuaserver.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PachageName: com.itcast.tanhuaserver.service.impl
 * @ClassName:
 * @Description: TODO
 * @Author: Hushi
 * @DateTime: 2021/2/1610:24
 * @Version 1.0
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 根据userId查询用户信息
     * @param userId 用户ID
     * @return 用户信息
     */
    @Override
    public UserInfo queryUserInfoById(Long userId) {
        QueryWrapper<UserInfo> query = new QueryWrapper<>();
        query.eq("user_id",userId);
        return userInfoMapper.selectOne(query);
    }

    /**
     * 查询用户信息列表
     * @param query 查询条件
     * @return 用户信息列表
     */
    @Override
    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> query) {
        return this.userInfoMapper.selectList(query);
    }

    @Override
    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        return this.userInfoMapper.update(userInfo, queryWrapper) > 0;
    }
}
